const fs = require('fs/promises');
const path = require('path');

exports.seed = async function(knex) {

  console.log(__dirname);

  const mainContent = await fs.readFile(path.join(__dirname, './text-page/main.md'), 'utf-8');
  
  const projectManagementContent = await fs.readFile(path.join(__dirname, './text-page/project-management.md'), 'utf-8');

  const notFoundContent = await fs.readFile(path.join(__dirname, './text-page/not-found.md'), 'utf-8');

  const projectSchema = {
    schema: {
      name: {desc: '项目名称', type: 'string'},
      desc: {desc: '项目描述', type: 'string'},
    },
    'entry-layout': [
      {row: ['name', 'desc']},
    ],
    'table-layout': {
      name: {width: 0.33},
      desc: {width: 0.67}
    }
  }

  const projectNavigateContent = {
    states: [{
      header: '我的项目',
      ...projectSchema,
      query: {
        name: 'project',
        cond: {}
      }
    }]
  }

  const projectCreateContent = {
    states: [{
      header: '我的项目',
      ...projectSchema,
    }]
  }

  const formContent = {
    states: {BASIC: {
      header: 'Basic Information',
      schema: {
        name: {type: 'text'},
        gender: {type: 'select', suggs:['male', 'female', 'former male', 'former female']},
        district: {type: 'select', suggs:[...Array(15)].map(e => Math.random().toString(36).slice(2, 10))},
        age: {type: 'number'},
      },
      query: {
        name: 'basic-info',
        cond: {},
      },
      layout: [
        {row: ['name', 'gender']},
        {row: ['district', 'age']}
      ],
      transRules: {
        OPTIONAL: {
          desc: 'Next step'
        }
      }
    }},
    initState: 'BASIC'
  }

  const tableContent = {
    states:{
      def: {
        schema: {
          name:  {desc: '姓名', type: 'string', width: 0.33, isDisabled: true, isFilterable: true, isSortable: true},
          age:   {desc: '年龄', type: 'numeric', width: 0.33, isDisabled: true, isFilterable: true, isSortable: true},
          assoc: {desc: '关联用户', type: 'select', width: 0.33, suggs: [
            '1', '2', '3', '4'
          ]},
          other: {desc: '其他', type: 'string', width: 0.33, isDisabled: true, isFilterable: true, isSortable: true},
        },
        query: {
          table: 'table-content',
          content: {user: 'local'},
        },
        layout: [
          {row:['name', 'age', 'other']},
          {row:['assoc']},
        ],
        header: 'Editing',
      }
    },
    initState: 'def'
  }


  const userContent = {
    states:{
      def: {
        schema: {
          id:  {desc: 'ID', type: 'string', width: 0.33},
          mail:  {desc: 'Mail', type: 'string', width: 0.33},
          pass:  {desc: 'pass', type: 'string', width: 0.33},
        },
        query: {
          name: 'user-list',
          cond: {},
        },
        layout: [
          {row:['mail', 'pass', 'id']}
        ],
        header: 'Editing',
      }
    },
    initState: 'def'
  }


  return knex('page-spec')
    .del()
    .then(() => {

      return knex('page-spec').insert();

    });
};
